/*
 * example2.c
 *
 *  Created on: Apr 1, 2011
 *      Author: makkalot
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "fibthread.h"

void* foo(void*);
void* bar(void*);

int main(int argc,char *argv[]){
	fibthread_t foo_t,bar_t;

	if(fibthread_create(&foo_t,NULL,foo,NULL)<0){
		printf("Error when creating foo \n");
		exit(EXIT_FAILURE);
	}

        	
	if(fibthread_create(&bar_t,NULL,bar,NULL)<0){
		printf("Error when creating bar \n");
		exit(EXIT_FAILURE);
	}

	printf("It should be working now ... \n");

	fibthread_loop();

	return 0;
}

void* foo(void* p){
	int i;
	for(i=0;i<1000000;i++){
		//printf("Hello from foo %d \n",i);
		printf("Hello from foo ---> %d\n",i);
		//sleep(2);
		fibthread_yield();
	}
	return NULL;
}

void* bar(void* p){
	int i;
	for(i=0;i<1000000;i++){
		//printf("Hello from bar %d\n",i);
		printf("Hello from bar --> %d \n",i);
		//sleep(1);
		fibthread_yield();
	}
	return NULL;
}

